/*
 * @Date         : 2022-06-29 10:44:15
 * @LastEditors  : zu1662
 * @LastEditTime : 2024-05-24 15:08:16
 * @Description  : 文章 数据实体
 *
 * Copyright © 2022 by zu1662, All Rights Reserved.
 */
import { ApiProperty } from '@nestjs/swagger';
import {
  Column,
  CreateDateColumn,
  Entity,
  JoinTable,
  PrimaryGeneratedColumn,
  UpdateDateColumn,
} from 'typeorm';

@Entity({ name: 'article' })
export class ArticleEntity {
  @ApiProperty()
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @ApiProperty()
  @Column({ charset: 'utf8mb4' })
  title: string;

  @ApiProperty()
  @Column({ default: null })
  cover: string; // 封面图

  @ApiProperty()
  @Column({ type: 'text', default: null, charset: 'utf8mb4' })
  summary: string; // 摘要，自动生成

  @ApiProperty()
  @Column({ type: 'mediumtext', default: null, charset: 'utf8mb4' })
  content: string; // 原始内容

  @ApiProperty()
  @Column({ type: 'mediumtext', default: null, charset: 'utf8mb4' })
  html: string; // 格式化内容，自动生成

  @ApiProperty()
  @Column({ type: 'mediumtext', default: null, charset: 'utf8mb4' })
  toc: string; // 格式化内容索引，自动生成

  // @ApiProperty()
  // @JoinTable()
  // category: CategoryEntity;

  // @ApiProperty()
  // @JoinTable()
  // tags: Array<TagEntity>;

  @ApiProperty()
  @Column('simple-enum', { enum: ['draft', 'publish'] })
  status: string; // 文章状态

  @ApiProperty()
  @Column({ type: 'int', default: 0 })
  views: number; // 阅读量

  @ApiProperty()
  @Column({ type: 'int', default: 0 })
  likes: number; // 喜欢数

  @ApiProperty()
  @Column({ type: 'boolean', default: false })
  isRecommended: boolean; // 是否推荐到首页

  @ApiProperty()
  @Column({ type: 'text', default: null, select: false, charset: 'utf8mb4' })
  password: string;

  @ApiProperty()
  @Column({ type: 'boolean', default: false })
  needPassword: boolean;

  @ApiProperty()
  @Column({ type: 'boolean', default: true })
  isCommentable: boolean; // 是否可以评论

  @ApiProperty()
  @Column({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  publishAt: Date; // 发布日期

  @ApiProperty()
  @CreateDateColumn({
    type: 'datetime',
    comment: '创建时间',
    name: 'create_at',
  })
  createAt: Date;

  @ApiProperty()
  @UpdateDateColumn({
    type: 'datetime',
    comment: '更新时间',
    name: 'update_at',
  })
  updateAt: Date;
}
